<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
{% include 'base/cssJs.html.twig' %}
<style type="text/css">
html {
    background-color: #393D49;
}
#login_box {
    position: absolute;
    width: 480px;
    height: 234px;
    margin-left: -240px;
    margin-top: -117px;
    left: 50%;
    top: 50%;
}
</style>
</head>
<body>
<div class="layui-card" id="login_box">
    <div class="layui-card-header layui-bg-green">请选择您要登录的用户组</div>
    <div class="layui-card-body" style="padding:50px;">
        <form class="layui-form layui-form-pane" method="post">
            <!---->
            <div class="layui-form-item">
                <label class="layui-form-label">用户组</label>
                <div class="layui-input-block">
                    <select name="group" id="group">
                        {% for group in list %}
                        <option value="{{ group.id }}">{{ group.dry_name }}</option>
                        {% endfor %}
                    </select>
                </div>
            </div>
            <!---->
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="default" id="submit">登录</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
            <!---->
        </form>
    </div>
</div>
<script>
layui.use(["form", "layer", "jquery", "cookies"], function(form, layer, $, cookies){
    form.on('submit(default)', function(){
        function success(json)
        {
            if(json.code > 0){
                layer.msg(json.msg);
            }
            else{
                cookies.setItem("group", data.groupId, null, "/");
                window.location.href = "/Admin/Home/index";
            }
        }

        var data = {
            "token": cookies.getItem("token"),
            "groupId": $("#group").val(),
            "device": "admin"
        };
        sendPostRequest("/Api/User/selectGroup", toFormData(data), success);
        return false;
    });
    if($("#group option").length == 1){
        $("#submit").trigger("click");
    }
});
</script>
</body>
</html>